/*
 ******************************
 * Object Oriented Programming in C
 *
 * Author: Laurent Deniau, Laurent.Deniau@cern.ch
 *
 * For more information, please see the paper:
 * http://home.cern.ch/ldeniau/html/oopc/oopc.html
 *
 ******************************
 */

#include <stdio.h>
#include <math.h>
#include <exception.h>

/* can also be #defined */
enum { no_exception, zero_divide, domain_error } exceptions;

double
div_(double a, double b)
{
  if (b == 0.0) throw(zero_divide);
  return a/b;
}

double
ln_(double a)
{
  if (a <= 0.0) throw(domain_error);
  return log(a);
}

int
main(int argc, char *argv[])
{
  double a, b;

  if (argc!=3) return EXIT_FAILURE;
  a = atof(argv[1]);
  b = atof(argv[2]);

  try {
    printf("ln(%g/%g) = %g\n", a, b, ln_(div_(a,b)));
  }
  catch(zero_divide) {
    printf("zero division\n");
  }
  catch(domain_error) {
    printf("domain error\n");
  }
  catch_any {
    printf("unknow exception no %d\n", exception);
  }
  endtry;

  return EXIT_SUCCESS;
}
